<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <!--
       -->
      <!-- <el-form-item label="养护机构" prop="field3">
        <el-input
          v-model="queryParams.field3"
          placeholder="请输入养护机构"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item label="隧道编码" prop="field1">
        <el-select
          v-model="queryParams.field1"
          placeholder="请输入隧道编码"
          clearable
          size="small">
          <el-option
            v-for="dict in suidaoList"
            :key="dict.id+''"
            :label="dict.field1"
            :value="dict.id+''"
          ></el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="隧道名称" prop="field2">
        <el-select v-model="queryParams.field2" placeholder="请选择隧道名称">
          <el-option
            v-for="dict in suidaoList"
            :key="dict.field2 +''"
            :label="dict.field2"
            :value="dict.field2+''"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="公路名称"  prop="field4">
        <el-select v-model="queryParams.field4" placeholder="请选择公路">
          <el-option
            v-for="item in gongluList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
            :disabled="item.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="里程桩号" prop="mileageNumber">
        <el-select v-model="queryParams.mileageNumber" placeholder="请选择里程桩号">
          <el-option
            v-for="dict in facilityList"
            :key="dict.mileageNumber+''"
            :label="dict.mileageNumber"
            :value="dict.mileageNumber+''"
            ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:tjjgrcxc:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"

          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:tjjgrcxc:edit']"
          >编辑/查看</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"

          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:tjjgrcxc:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"

          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:tjjgrcxc:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="tjjgrcxcList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="隧道编码" align="center" prop="field1">
        <!-- <template slot-scope="scope">
          <dict-tag :options="dict.type.shzt" :value="scope.row.field1" />
        </template> -->
      </el-table-column>
      <el-table-column label="隧道名称" align="center" prop="field2" />
      <el-table-column label="养护机构" align="center" prop="field3" />
      <el-table-column label="路线名称" align="center" prop="field4" />
<!--      <el-table-column label="路线编码" align="center" prop="field5" />-->
      <el-table-column
        label="上次检查日期"
        align="center"
        prop="field6"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="本次检查日期"
        align="center"
        prop="field7"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.field7, "{y}-{m}-{d} {h}:{m}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="里程桩号" align="center" prop="field8" />
      <el-table-column label="结构名称" align="center" prop="field9" />
      <el-table-column label="异常位置" align="center" prop="field10" />
      <!-- <el-table-column label="检查内容" align="center" prop="field11" />
      <el-table-column label="状况描述" align="center" prop="field12" /> -->
      <!-- <el-table-column label="图片" align="center" prop="field13" /> -->
      <el-table-column label="时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{m}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:tjjgrcxc:edit']"
            >编辑/查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:tjjgrcxc:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或编辑/查看土建结构日常巡查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
        <el-form-item label="隧道编码" prop="field1">
          <el-select v-model="form.field1" placeholder="请选择隧道编码">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.id+''"
              :label="dict.field1"
              :value="dict.id+''"
            ></el-option>
          </el-select>
        </el-form-item>
          </el-col>
          <el-col :span="12">
        <el-form-item label="隧道名称" prop="field2">
          <el-select v-model="form.field2" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field2 +''"
              :label="dict.field2"
              :value="dict.field2+''"
            ></el-option>
          </el-select>
        </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="养护机构" prop="field3">
          <el-input v-model="form.field3" placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="公路名称"  prop="field4">
          <el-select v-model="form.field4" placeholder="请选择公路名称">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field2"
              :value="item.field2 + ''"
              :disabled="item.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="路线编码" prop="field5">-->
<!--          <el-input v-model="form.field5" placeholder="请输入路线编码" />-->
<!--        </el-form-item>-->
        <el-form-item label="上次检查日期" prop="field6">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field6"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择上次检查日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本次检查日期" prop="field7">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field7"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择本次检查日期"
          >
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="里程桩号" prop="field8">-->
<!--          <el-input v-model="form.field8" placeholder="请输入里程路桩" />-->
<!--        </el-form-item>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="里程桩号" prop="field8">
              <el-select v-model="form.field8" placeholder="请选择里程桩号">
                <el-option
                  v-for="dict in facilityList"
                  :key="dict.mileageNumber+''"
                  :label="dict.mileageNumber"
                  :value="dict.mileageNumber+''"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结构名称" prop="field9">
              <el-select v-model="form.field9" placeholder="请选择结构名称" clearable :style="{width: '100%'}">
                <el-option v-for="(item, index) in fieldfacility" :key="index" :label="item.label"
                           :value="item.value" :disabled="item.disabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="异常位置" prop="field10">
          <el-input v-model="form.field10" placeholder="请输入异常位置" />
        </el-form-item>
        <el-form-item label="检查内容" prop="field11">
          <el-input
            v-model="form.field11"
            type="textarea"
            placeholder="请输入检查内容"
          />
        </el-form-item>
        <el-form-item label="状况描述" prop="field12">
          <el-input
            v-model="form.field12"
            type="textarea"
            placeholder="请输入状况描述"
          />
        </el-form-item>
        <el-form-item label="图片">
          <imageUpload v-model="form.field13" />
        </el-form-item>
        <el-form-item label="检查人" prop="field14">
          <el-input
            v-model="form.field14"
            type="textarea"
            placeholder="请输入检查人"
          />
        </el-form-item>
        <el-form-item label="记录人" prop="field15">
          <el-input v-model="form.field15" placeholder="请输入记录人" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTjjgrcxc,
  getTjjgrcxc,
  delTjjgrcxc,
  addTjjgrcxc,
  updateTjjgrcxc,
  exportTjjgrcxc,
} from "@/api/biz/tjjgrcxc";
import {
  listSuidao
} from "@/api/biz/suidao";
import { listGonglu } from "@/api/biz/gonglu";
import {listFacility} from "@/api/civil/facility";

export default {
  name: "Tjjgrcxc",
  dicts: ["shzt"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 土建结构日常巡查表格数据
      tjjgrcxcList: [],
      // 隧道信息表格数据
      suidaoList: [],
      //道路列表
      gongluList: [],
      //土建结构设施列表
      facilityList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: null,
        date1: null,
      },
      // 表单参数
      form: {},

      fieldfacility: [{
        "label": "洞口",
        "value": "洞口"
      }, {
        "label": "洞门",
        "value": "洞门"
      },{
        "label": "衬砌",
        "value": "衬砌"
      },{
        "label": "路面",
        "value": "路面"
      },{
        "label": "检修道",
        "value": "检修道"
      },{
        "label": "排水设施",
        "value": "排水设施"
      },{
        "label": "吊顶及预埋件",
        "value": "吊顶及预埋件"
      },{
        "label": "装饰物",
        "value": "装饰物"
      }, {
        "label": "交通标志/标线",
        "value": "交通标志/标线"
      }
      ],

      // 表单校验
      rules: {
        field1: [
          { required: true, message: "隧道编码不能为空", trigger: "change" },
        ],
        field2: [
          { required: true, message: "隧道名称不能为空", trigger: "blur" },
        ],
        field3: [
          { required: true, message: "养护机构不能为空", trigger: "blur" },
        ],
        field4: [
          { required: true, message: "公路名称不能为空", trigger: "blur" },
        ],
        // field5: [
        //   { required: true, message: "路线编码不能为空", trigger: "blur" },
        // ],
        field6: [
          { required: true, message: "上次检查日期不能为空", trigger: "blur" },
        ],
        field7: [
          { required: true, message: "本次检查日期不能为空", trigger: "blur" },
        ],
        field8: [
          { required: true, message: "里程桩号不能为空", trigger: "blur" },
        ],
        field9: [
          { required: true, message: "结构名称不能为空", trigger: "blur" },
        ],
        field10: [
          { required: true, message: "异常位置不能为空", trigger: "blur" },
        ],
        field11: [
          { required: true, message: "检查内容不能为空", trigger: "blur" },
        ],
        field12: [
          { required: true, message: "状况描述不能为空", trigger: "blur" },
        ],
        // field13: [{ required: true, message: "图片不能为空", trigger: "blur" }],
        field14: [
          { required: true, message: "检查人不能为空", trigger: "blur" },
        ],
        field15: [
          { required: true, message: "记录人不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
      listSuidao({}).then((response) => {
        this.suidaoList = response.rows;
      });
    listGonglu({}).then((response) => {
      this.gongluList = response.rows;
    });
    listFacility({}).then((response) => {
      this.facilityList = response.rows;
    });
  },
  methods: {
    /** 查询土建结构日常巡查列表 */
    getList() {
      this.loading = true;
      listTjjgrcxc(this.queryParams).then((response) => {
        this.tjjgrcxcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: "0",
        date1: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加土建结构日常巡查";
    },
    /** 编辑/查看按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTjjgrcxc(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "编辑/查看土建结构日常巡查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTjjgrcxc(this.form).then((response) => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTjjgrcxc(this.form).then((response) => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delTjjgrcxc(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有土建结构日常巡查数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportTjjgrcxc(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
